import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import seaborn as sns

income = pd.read_excel(r'audlt_test.xlsx')
plt.style.use('seaborn-talk')
# fig, axes = plt.subplots(2, 1)
# income.age[income.income == '<=50K'].plot(kind = 'kde', label = '<=50K', ax = axes[0], legend = True, linestyle = '-')
# income.age[income.income == '>50K'].plot(kind = 'kde', label = '>50K', ax = axes[0], legend = True, linestyle = '--')
#
# income['hours-per-week'][income.income == '<=50K'].plot(kind = 'kde', label = '<=50K', ax = axes[1], legend = True, linestyle = '-')
# income['hours-per-week'][income.income == '>50K'].plot(kind = 'kde', label = '>50K', ax = axes[1], legend = True, linestyle = '--')
#
# plt.show()
relationship = pd.DataFrame(income.groupby(by = ['relationship','income']).aggregate(np.size).loc[:,'age'])
print(relationship)
relationship = relationship.reset_index()
print(relationship)
relationship.rename(columns={'age':'counts'}, inplace=True)
print(relationship)
relationship.sort_values(by = ['relationship','counts'], ascending=False, inplace=True)
print(relationship)
plt.figure(figsize=(9,5))
sns.barplot(x="relationship", y="counts", hue = 'income', data=relationship)
plt.show()